﻿using System;
using System.Linq;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Web.Mvc;
using AlmaDatabase;

namespace Alma.Models
{
    public class EmptyUser
    {
        [ReadOnly(true)]
        [HiddenInput]
        public long ID { get; set; }

        [ReadOnly(true)]
        [HiddenInput]
        public int? IsAdmin { get; set; }

        [Required]
        [DataType(DataType.EmailAddress)]
        [DisplayName("E-Mail")]
        public string Email { get; set; }
        
        [Required]
        [DataType(DataType.Text)]
        [DisplayName("Prenom")]
        public string Firstname { get; set; }
        
        [Required]
        [DataType(DataType.Text)]
        [DisplayName("Nom de Famille")]
        public string Name { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [DisplayName("Adresse")]
        public string Address { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [DisplayName("Pays")]
        public string Country { get; set; }

        [Required]
        [DataType(DataType.Text)]
        [DisplayName("Ville")]
        public string Town { get; set; }

        [Required]
        [DisplayName("Code Postal")]
        public int? Zipcode { get; set; }

        [ReadOnly(true)]
        [HiddenInput]
        public string OpenId
        {
            get;
            set;
        }
        public List<ShopModel> shopList { get; set; }

        public EmptyUser(User user)
        {
            ID = user.ID;
            Address = user.Address;
            Country = user.Country;
            Email = user.Email;
            Firstname = user.Firstname;
            Name = user.Name;
            Town = user.Town;
            Zipcode = user.Zipcode;
            IsAdmin = user.IsAdmin;
            /*shopList*/
            shopList = new List<ShopModel>();
            using (var context = new AlmaDBEntities())
            {
                var shops = context.Shops;
                var list = from shop in shops
                       where (shop.ID_User != null &&
                              shop.ID_User == ID)
                           orderby shop.ID
                           select shop;
                foreach (var shope in list)
                    shopList.Add(new ShopModel(shope));
            }
            
        }

        public EmptyUser()
        {
            
        }
    }

    public class UsersList
    {
        public List<EmptyUser> list;
    }
}